let sendNum = 0;
export const request = (config) => {
  const baseUrl = 'https://api-hmugo-web.itheima.net/api/public/v1';
  sendNum++;
  if(sendNum){
    wx.showLoading({
      title: '加载中',
    })
  }
  return new Promise((resolve, reject) => {
    wx.request({
      ...config,
      url: baseUrl + config.url,
      success:(res) => {
        if(--sendNum <= 0){
          wx.hideLoading();
        }
        resolve(res.data)
      },
      fail:(err) =>{
        wx.showToast({
          title: '加载失败',
          icon: 'error'
        })
        reject(err)
      }
    })
  })
}